import { defineStore, StoreDefinition } from 'pinia'
interface UserInfo {
  headImage: string
  headImageThumb: string
  nickName: string
  phone: string
  sex: string
  shipId: string
  shipName: string
  tenantName: string
  userId: string
  userName: string
  token: string
}
export const useUserStore: any = defineStore({
  id: 'user',
  state: () => {
    return {
      token: '',
      userInfo: {
        headImage: '',
        headImageThumb: '',
        nickName: '',
        phone: '',
        sex: '',
        shipId: '',
        shipName: '',
        tenantName: '',
        userId: '',
        userName: '',
        token: ''
      },
      sysUser: {},
      shipInfo: {},
      sysPermissionList: [], // PC动态路由数据
      sysPermissionMap: {}
    }
  },
  actions: {
    // 更新用户信息
    setUserInfo(data: UserInfo) {
      this.userInfo = data
    },
    setToken(payload: string) {
      this.token = payload
    },
    getUserInfo() {}
  },
  getters: {
    hasPermission() {
      return (permission: string) => {
        // @ts-ignore
        return !!this.sysPermissionMap[permission]
      }
    }
  }
  // persist: {
  //   // 开启持久化
  //   enabled: 'false',
  //   H5Storage: window?.localStorage
  // }
})
